using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace StudentManagementApplication
{
    public partial class FrmStudentMarksReport : Form
    {
        List<Entities.Class> classList = new List<Entities.Class>();
        List<Entities.Course> courseList = new List<Entities.Course>();
        List<Entities.Marks> marksList = new List<Entities.Marks>();
        Business.ClassService classService = new Business.ClassService();
        Business.CourseService courseService = new Business.CourseService();
        Business.MarksService marksService = new Business.MarksService();
        report2 rpt = null;
        string sClassID = string.Empty;
        string sCourseID = string.Empty;
        
        private void InitializeClass()
        {
            cmbClass.Items.Clear();
            classList = classService.GetClassByCourseID(sCourseID);
            foreach (Entities.Class _class in classList)
                cmbClass.Items.Add(_class.ClassID + "--" + _class.ClassName);
            cmbClass.SelectedIndex = 0;
        }

        private void InitializeCourse()
        {
            courseList = courseService.GetAllCourses();
            foreach (Entities.Course course in courseList)
                cmbCourse.Items.Add(course.CourseID + "--" + course.CourseName);
        }

        private void ShowReport()
        {
            using (DataTable dataTable = marksService.GetMarksByCourseIDAndClassID1(sCourseID,sClassID))
            {
                rpt = new report2();
                rpt.SetDataSource(dataTable);
                rpt.SetParameterValue("sCourseName", cmbCourse.Text.Substring(7));
                rpt.SetParameterValue("sClassName", cmbClass.Text.Substring(8));
                crystalReportViewer1.ReportSource = rpt;
                crystalReportViewer1.Refresh();
            }
        }

        public FrmStudentMarksReport()
        {
            InitializeComponent();
        }

        private void FrmStudentMarksReport_Load(object sender, EventArgs e)
        {
            InitializeCourse();
        }

        private void cmbClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            sClassID = cmbClass.Text.Substring(0, 6);
        }

        private void cmbCourse_SelectedIndexChanged(object sender, EventArgs e)
        {
            sCourseID = cmbCourse.Text.Substring(0, 5);
            cmbClass.Enabled = true;
            InitializeClass();
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            ShowReport();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}